package client;

import info.Message;

import java.io.IOException;

import users.Student;

import common.ChatIF;

public class StudentClient extends AESSClient
{
	
	
	private String startDate;
	private String[] classCode = new String[6];
	private String[] row = new String[6];
	private String[] col = new String[6];
	
	String [][]subnum = new String[27][6];
	
	public Student user;
	
	public StudentClient(String host, int port, ChatIF clientUI)
			throws IOException {
		super(host, port, clientUI);
		// TODO Auto-generated constructor stub
	}

	
	
	
	public void requireStartTest()
	{
		
		try {
			sendToServer("#requireStartTest");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public void requireDesidedDay()
	{
		
		try {
			sendToServer("#requireDesidedDay");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public String getStartDate()
	{
		
		return startDate;
		
	}
	
	public String[] getClassCode()
	{
		
		return classCode;
		
	}
	
	public String[] getRow()
	{
		
		return row;
		
	}
	public String[] getCol()
	{
		
		return col;
		
	}
	
	public void testNumOfSubject(int row, int col, String subnum,String val)
	{
		
		this.subnum[row][col]=subnum+","+val;
		
	}
	
	public void classNumOfSubject(int row, int col, String subnum,String val)
	{
		
		this.subnum[row][col]=subnum+","+val;
		
	}
	
	public void deleteSubject(int row, int col)
	{
		
		this.subnum[row][col]="";
		
	}
	
	public void sendSchedule()
	{
		
		try {
			boolean [][]subtable = new boolean[26][5];
			
			for(int i=1;i<=26;i++){
				for(int j=1;j<=5;j++){
					if(subnum[i][j] == null)
						subtable[i-1][j-1] = true;
					else
						subtable[i-1][j-1] = false;
				}
			}
			
			Message msg = new Message();
			msg.msgHeader="#sendSchedule";
			msg.msgBody = subtable;
			msg.extraInfo = this.user;
			
			System.out.println(this.user);
			
			
			System.out.println(((Student)msg.extraInfo).id + "," + ((Student)msg.extraInfo).name);
			
			sendToServer(msg);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void handleMessageFromServer(Object msg) 
	{
		  Message newMsg = (Message)msg;
		  
		  
		  String response = newMsg.msgHeader;
	
		  
		  System.out.println(response);
		  
		  if(response.contains("#startday")){                     //시험시작날짜 받음
			  startDate = response.split(":")[1];
			  System.out.println("startDate:" + startDate);
			  
		  }
		  if(response.contains("#desidedSubInfo")){                     //확정된 시험날짜 과목번호 받음
			  String[] res = new String[10];
			  
			  res = response.split(":");
			 
			  
			  classCode[0] = res[1];                    //#desidedSubInfo:과목번호:row:col 
			  row[0] = res[2];
			  col[0] = res[3];
			  classCode[1] = res[4];                    
			  row[1] = res[5];
			  col[1] = res[6];
			  classCode[2] = res[7];                
			  row[2] = res[8];
			  col[2] = res[9];
			  classCode[3] = res[10];                    
			  row[3] = res[11];
			  col[3] = res[12];
			  classCode[4] = res[13];                  
			  row[4] = res[14];
			  col[4] = res[15];
			  classCode[5] = res[16];                  
			  row[5] = res[17];
			  col[5] = res[18];
			  
			  System.out.println("classCode:" + classCode+" row:" + row+" col:" + col);

			  
			
		  }
		  
		  
		  
	
	}
}

